package com.btobtob.a.biz.user.controller;

import com.btobtob.a.biz.user.converter.Demo3Converter;
import com.btobtob.a.biz.user.converter.WeatherForecastConverter;
import com.btobtob.a.biz.user.dto.clientobject.Demo1CO;
import com.btobtob.a.biz.user.dto.command.Demo1Cmd;
import com.btobtob.a.biz.user.entity.WeatherForecast;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.btobtob.a.biz.user.dto.clientobject.WeatherForecastCO;
import com.btobtob.a.biz.user.dto.command.WeatherForecastCmd;

@Slf4j
@RequestMapping("/receiver")
@Tag(name = "receiver", description = "receiver")
@RestController
@Validated
@ResponseBody
public class ReceiverController {

    @Resource
    private WeatherForecastConverter weatherForecastConverter;

    @GetMapping(value = "/get")
    public String get() {
        return "ok";
    }

    @PostMapping(value = "/post")
    public Demo1CO post(@RequestBody Demo1Cmd cmd) {
        Demo1CO co = new Demo1CO();
        co.setMyNo(cmd.getMyNo());
        co.setMyName(cmd.getMyName());
        return co;
    }
    
    @PostMapping(value = "/post1")
    public WeatherForecastCO post1(@RequestBody WeatherForecastCmd cmd) {
//        WeatherForecastCO co = new WeatherForecastCO();
//        co.setId(cmd.getId());
//        co.setZonedDatetime(cmd.getZonedDatetime());
//        co.setLocalDatetime(cmd.getLocalDatetime());
//        co.setLocalDate(cmd.getLocalDate());
////        co.setLocalTime(cmd.getLocalTime());
//        co.setTemperatureC(cmd.getTemperatureC());
//        co.setSummary(cmd.getSummary());
        WeatherForecast entity = weatherForecastConverter.from(cmd);
        //todo
        return weatherForecastConverter.to(entity);
    }

    @PostMapping(value = "/post2")
    public List<WeatherForecastCO> post2(@RequestBody List<WeatherForecastCmd> cmds) {
        List<WeatherForecastCO> cos = new ArrayList<WeatherForecastCO>();
        for (WeatherForecastCmd cmd : cmds) {
            WeatherForecastCO co = new WeatherForecastCO();
            co.setId(cmd.getId());
            co.setZonedDatetime(cmd.getZonedDatetime());
            co.setLocalDatetime(cmd.getLocalDatetime());
            co.setLocalDate(cmd.getLocalDate());
//            co.setLocalTime(cmd.getLocalTime());
            co.setTemperatureC(cmd.getTemperatureC());
            co.setSummary(cmd.getSummary());
            cos.add(co);
        }
        return cos;
    }

}
